package day20180128.testProxyDynamic;

/**
 * Created by 14394 on 2018/1/28.
 */
public class ProxyLogin implements ILogin {
    //这里用作动态代理的辅助类
    private ILoginImpl target;

    public ProxyLogin(ILoginImpl target) {
        this.target = target;
    }

    public ProxyLogin() {
    }

    @Override
    public void login() {
        long begin = System.currentTimeMillis();
        target.login();

        long end = System.currentTimeMillis();
        System.out.println("耗费时间：" +(end-begin)+"毫秒");
    }

    @Override
    public void logout() {

        long begin = System.currentTimeMillis();
        target.logout();

        long end = System.currentTimeMillis();
        System.out.println("耗费时间：" +(end-begin)+"毫秒");

    }

    public static void main(String[] args) {
        try {
            Class c = Class.forName("day20180128.testProxyDynamic.ProxyLogin");
            Object o = c.newInstance();
            ProxyLogin p = (ProxyLogin) o;
            p.login();
            p.logout();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        }
    }
}
